package cn.lf.utils;

import cn.lf.constant.ResponseCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("响应类")
public class ResponseModel<T> {

    @ApiModelProperty("响应状态码")
    private int code;

    @ApiModelProperty("响应信息")
    private String msg;

    @ApiModelProperty("响应数据")
    private T data;

    public ResponseModel(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseModel(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseModel(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public ResponseModel(String msg, T data) {
        this.code = ResponseCodeEnum.SUCCESS.getCode();
        this.msg = msg;
        this.data = data;
    }

    public static ResponseModel getResponseModel(ResponseCodeEnum codeEnum){
        return new ResponseModel(codeEnum.getCode(),codeEnum.getMsg());
    }

    public static ResponseModel getSysError(){
        return getResponseModel(ResponseCodeEnum.SYS_ERROR);
    }

    public static  <T> ResponseModel<T> buildSuccessResult(String msg, T data) {
        return new ResponseModel<T>(ResponseCodeEnum.SUCCESS.getCode(), msg, data);
    }

    public static  <T> ResponseModel<T> buildSuccessResult(T data) {
        return new ResponseModel<T>(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(), data);
    }

    public static  <T> ResponseModel<T> buildSuccessResult(String msg) {
        return new ResponseModel<T>(ResponseCodeEnum.SUCCESS.getCode(), msg);
    }

    public static ResponseModel buildSuccessResult() {
        return new ResponseModel(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg());
    }
}
